package smu.ui.widget;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ExpandableListActivity;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;

import smu.ui.R;
public class ExpandableList extends ExpandableListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.expandable_main);
		
		ArrayList<HashMap<String,String>> groups = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> group1 = new HashMap<String,String>();
		group1.put("groupId","groupId1");
		group1.put("groupName","groupName1");
		groups.add(group1);
		HashMap<String,String> group2 = new HashMap<String,String>();
		group2.put("groupId","groupId2");
		group2.put("groupName","groupName2");
		groups.add(group2);
		
		ArrayList<ArrayList<HashMap<String,String>>> childs = new ArrayList<ArrayList<HashMap<String,String>>>();
		
		ArrayList<HashMap<String,String>> child1 = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> child1Data1 = new HashMap<String,String>();
		child1Data1.put("childId","child1Id1");
		child1Data1.put("childName","child1Name1");
		child1.add(child1Data1);
		HashMap<String,String> child1Data2 = new HashMap<String,String>();
		child1Data2.put("childId","child1Id2");
		child1Data2.put("childName","child1Name2");
		child1.add(child1Data2);
		childs.add(child1);
		
		ArrayList<HashMap<String,String>> child2 = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> child2Data1 = new HashMap<String,String>();
		child2Data1.put("childId","child2Id1");
		child2Data1.put("childName","child2Name1");
		child2.add(child2Data1);
		childs.add(child2);
		
		SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
				ExpandableList.this,
				groups, R.layout.expandable_group, new String[]{"groupId","groupName"},new int[]{R.id.groupId,R.id.groupName},
				childs, R.layout.expandable_child, new String[]{"childId","childName"},new int[]{R.id.childId,R.id.childName}
		); 
			
		setListAdapter(adapter);
		
	}

	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		// TODO Auto-generated method stub
		Toast.makeText(ExpandableList.this, "groupPosition:"+groupPosition+"childPosition:"+childPosition, Toast.LENGTH_SHORT).show();
		return super.onChildClick(parent, v, groupPosition, childPosition, id);
	}
	
	
	
}
